package com.carambatv.android.adapter;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.carambatv.android.db.RssQuery;
import com.carambatv.android.utils.DateUtil;

public class RssAdapter extends CursorAdapter {

	private LayoutInflater mInflater;

	public RssAdapter(Context context, Cursor c) {
		super(context, c, false);
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}

	@Override
	public void bindView(View view, final Context context, final Cursor cursor) {
		final YTubeViewHolder listItem = (YTubeViewHolder) view.getTag();
		final String title1 = getCursor().getString(RssQuery.TITLE);
		final long pubDate = getCursor().getLong(RssQuery.PUBDATE);
		listItem.title1.setText(title1);
		listItem.title2.setText(DateUtil.parseToStringExpand(pubDate));

	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		View view = mInflater.inflate(android.R.layout.simple_list_item_2, null);
		final YTubeViewHolder listItem = new YTubeViewHolder();
		listItem.title1 = (TextView) view.findViewById(android.R.id.text1);
		listItem.title2 = (TextView) view.findViewById(android.R.id.text2);

		view.setTag(listItem);
		return view;

	}

	public class YTubeViewHolder {
		TextView title1;
		TextView title2;

	}

}
